<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelUserItemDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelUserItemRequest;
use App\Http\Requests\UpdateChannelUserItemRequest;
use App\Repositories\ChannelUserItemRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelUserItemController extends AppBaseController
{
    /** @var  ChannelUserItemRepository */
    private $channelUserItemRepository;

    public function __construct(ChannelUserItemRepository $channelUserItemRepo)
    {
        $this->channelUserItemRepository = $channelUserItemRepo;
    }

    /**
     * Display a listing of the ChannelUserItem.
     *
     * @param ChannelUserItemDataTable $channelUserItemDataTable
     * @return Response
     */
    public function index(ChannelUserItemDataTable $channelUserItemDataTable)
    {
        return $channelUserItemDataTable->render('backend.channel_user_items.index');
    }

    /**
     * Show the form for creating a new ChannelUserItem.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_user_items.create');
    }

    /**
     * Store a newly created ChannelUserItem in storage.
     *
     * @param CreateChannelUserItemRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelUserItemRequest $request)
    {
        $input = $request->all();

        $channelUserItem = $this->channelUserItemRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel User Item']));

        return redirect(route('channelUserItems.index'));
    }

    /**
     * Display the specified ChannelUserItem.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelUserItem = $this->channelUserItemRepository->findWithoutFail($id);

        if (empty($channelUserItem)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel User Item']));

            return redirect(route('channelUserItems.index'));
        }

        return view('backend.channel_user_items.show')->with('channelUserItem', $channelUserItem);
    }

    /**
     * Show the form for editing the specified ChannelUserItem.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelUserItem = $this->channelUserItemRepository->findWithoutFail($id);

        if (empty($channelUserItem)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel User Item']));

            return redirect(route('channelUserItems.index'));
        }

        return view('backend.channel_user_items.edit')->with('channelUserItem', $channelUserItem);
    }

    /**
     * Update the specified ChannelUserItem in storage.
     *
     * @param  int              $id
     * @param UpdateChannelUserItemRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelUserItemRequest $request)
    {
        $channelUserItem = $this->channelUserItemRepository->findWithoutFail($id);

        if (empty($channelUserItem)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel User Item']));

            return redirect(route('channelUserItems.index'));
        }

        $channelUserItem = $this->channelUserItemRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel User Item']));

        return redirect(route('channelUserItems.index'));
    }

    /**
     * Remove the specified ChannelUserItem from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelUserItem = $this->channelUserItemRepository->findWithoutFail($id);

        if (empty($channelUserItem)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel User Item']));

            return redirect(route('channelUserItems.index'));
        }

        $this->channelUserItemRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel User Item']));

        return redirect(route('channelUserItems.index'));
    }
}
